<?php
namespace Core\Utils\Upload;
use OSS\OssClient;
use OSS\Core\OssException;
class aliOssUpload
{
    public function upload($filepath,$savename){
        // 从环境变量中获取访问凭证。运行本代码示例之前，请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
        $accessKeyId = "LTAI5tG32eUNrHL4ybEoYRAD";
        $accessKeySecret = "Mht60NqHFQntuljrdTb4rvaffk2HCx";
// Endpoint以杭州为例，其它Region请按实际情况填写。
        $endpoint = "oss-cn-hongkong.aliyuncs.com";
// 填写Bucket名称，例如examplebucket。
        $bucket= "linglongshop";
// <yourObjectName>表示上传文件到OSS时需要指定包含文件后缀，不包含Bucket名称在内的完整路径，例如abc/efg/123.jpg。
        //$content = "Hi, OSS.";
        try {
            $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
            //$ossClient->putObject($bucket, $object, $content);
            $result = $ossClient->uploadFile($bucket, $savename, $filepath);
        } catch (OssException $e) {
            return $e->getMessage();
        }
        return $result;
    }
}




